import { Actions } from 'react-native-router-flux';

// antd 按需加载
import { Toast } from '@ant-design/react-native';

import store from '../../../store/store.js'
import * as ActionTypes from '../../../constants/constants.js'
import { isUser, isWxUser, path, saveData, loadData, removeData, requstPromise } from '../../../util/utils.js'
import request from '../../../api/request.js'

export async function generateOrder(options) {
    const { dispatch } = this.props
    const res = await request.PortalOrderController.generateOrder(options)
    if (res.error) {

        return
    }
    return requstPromise(res)
}


export async function generateBehalfOrder(options) {
    const { dispatch } = this.props
    const res = await request.BehalfController.generateBehalfOrder(options)
    if (res.data.code == 200) {
        Toast.success('下单成功，客服会在一个工作日内处理您的订单。', 2, () => {
            Actions.orderList()
        }, false)
    } else {
        Toast.fail('提交失败', 1, null, false)
    }
    return requstPromise(res)
}


export async function addOrder(options) {
    const { dispatch } = this.props
    const res = await request.BehalfController.addOrder(options)
    return requstPromise(res)
}




export async function pay(options) {
    const { dispatch } = this.props
    const res = await request.PortalOrderController.pay(options)
    if (res.error) {
        return
    }

    if (res.data.code != 200) {
        Toast.fail(res.data.message, 1, null, false)
        return
    }
    return requstPromise(res)
}
